package main

import (
	"github.com/go-gin-admin/global"
	"github.com/go-gin-admin/middleware"
	"github.com/go-gin-admin/pkg/elasticsearch"
	"github.com/go-gin-admin/pkg/kafka"
	"github.com/go-gin-admin/pkg/taillog"
	"github.com/go-gin-admin/router"
)

func init() {
	global.InitViper()
	global.InitMysql()
	global.InitMinio()
	middleware.InitLogger()
	global.InitEtcd() // 初始化etcd连接
	elasticsearch.InitES("127.0.0.1:9200")

	kafka.InitClient([]string{"127.0.0.1:9092"}) // 初始化kafka client
	kafka.InitConsumer([]string{"127.0.0.1:9092"},"web_log")
}

func main() {

	// 主程序结束之前关闭gorm
	defer global.GDB.Close()
	defer middleware.Logger.Sync()
	defer global.EtcdCli.Close()
	defer kafka.KafkaClient.Close()

	routes := router.RegisterRoutes()
	taillog.NewTailTask("./log/web_log.log", "web_log")



	routes.Run(":8899")
}
